package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.common.entity.Role;

import java.util.List;

public interface RoleMapper {

    // 插入新角色
    @Insert("INSERT INTO role (tenant_id, role_name, description, created_at, updated_at) " +
            "VALUES (#{tenantId}, #{roleName}, #{description}, #{createdAt}, #{updatedAt})")
    void insertRole(Role role);

    // 根据ID查询角色
    @Select("SELECT * FROM role WHERE role_id = #{roleId} AND deleted_at IS NULL")
    Role getRoleById(@Param("roleId") Long roleId);

    // 查询某租户下的所有角色
    @Select("SELECT * FROM role WHERE tenant_id = #{tenantId} AND deleted_at IS NULL")
    List<Role> getRolesByTenantId(@Param("tenantId") Long tenantId);

    // 逻辑删除角色
    @Update("UPDATE role SET deleted_at = NOW() WHERE role_id = #{roleId}")
    void deleteRole(@Param("roleId") Long roleId);
}
